//
//  ViewController.m
//  Calendar
//
//  Created by XiaoFeng on 2016/11/22.
//  Copyright © 2016年 XiaoFeng. All rights reserved.
//

#import "ViewController.h"

#import "XFCalendarView.h"

@interface ViewController ()

@property (nonatomic ,strong ) XFCalendarView *calendarView;

@property (nonatomic ,strong ) UIButton *calendarBtn;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CGSize size = [UIScreen mainScreen].bounds.size;
    
    _calendarView = [[XFCalendarView alloc] init];
    _calendarView.frame = CGRectMake(10, 30, size.width-20, 200);
    [self.view addSubview:_calendarView];
    
    //设置已经签到的天数日期
    NSMutableArray* _signArray = [[NSMutableArray alloc] init];
    [_signArray addObject:[NSNumber numberWithInt:1]];
    [_signArray addObject:[NSNumber numberWithInt:5]];
    [_signArray addObject:[NSNumber numberWithInt:9]];
    [_signArray addObject:[NSNumber numberWithInt:13]];
    _calendarView.signArray = _signArray;
    
    
    _calendarView.date = [NSDate date];
    
    //1.点击日历数字事件
    
    NSDateComponents *comp = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:[NSDate date]];
    
    //日期点击事件
    __weak __typeof(self) weakSelf = self;
    _calendarView.calendarBlock =  ^(NSInteger day, NSInteger month, NSInteger year){
        if ([comp day]==day) {
            //根据自己逻辑条件 设置今日已经签到的style 没有签到不需要写
            [weakSelf changStatus];
        }
    };
    
    
    //2.点击外部按钮事件
    
    _calendarBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _calendarBtn.frame = CGRectMake(10, CGRectGetMaxY(_calendarView.frame), size.width - 20, 40);
    _calendarBtn.backgroundColor = [UIColor orangeColor];
    [_calendarBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_calendarBtn setTitle:@"签到" forState:UIControlStateNormal];
    [_calendarBtn addTarget:self action:@selector(changStatus) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_calendarBtn];

    
}


- (void)changStatus{

    NSLog(@"=======%@",_calendarView.date);
    
    [_calendarView setStyle_Today_Signed:_calendarView.dayButton];
    _calendarBtn.backgroundColor = [UIColor lightGrayColor];
    [_calendarBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_calendarBtn setTitle:@"已签到" forState:UIControlStateNormal];
    _calendarBtn.enabled = NO;

}





@end
